﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data.Models.Center;
using ZHDJ.Data.Models.Common;
using ZHDJ.Data.Models.JoinParty;
using ZHDJ.Data.Models.Questionnaire;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.Portal
{
    public partial class PublicMessageMore : UseMorePageMasterPage
    {
        /// <summary>
        /// 页数
        /// </summary>
        private string PageIndex
        {
            get
            {
                return this.Request["PageIndex"] ?? "";
            }
        }

        /// <summary>
        /// 每页条数
        /// </summary>
        private string PageSize
        {
            get
            {
                return this.Request["PageSize"] ?? "";
            }
        }
        private string DataCount
        {
            get
            {
                return this.Request["DataCount"] ?? "";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!string.IsNullOrEmpty(this.PageIndex))
            {
                this.WriteList();
            }
            else if (!string.IsNullOrEmpty(this.DataCount))
            {
                WriteDataCount();

            }
            if (!IsPostBack)
            {
                CheckLogin(true);
                LoadData();
            }

        }
        public void LoadData()
        {

        }

        private void WriteList()
        {
            DataTable dt = partyjoinpublicity.GetListData(Convert.ToInt32(this.PageIndex),
                Convert.ToInt32(PageSize)).Tables[0];

            dt.Columns.Add("CreateTime2", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                switch (dr["StepID"].ToString())
                {
                    case "JoinStep4": dr["ID"] = "JoinParty/Activists.aspx?AppllicationID=" + dr["AppllicationID"].ToString() + "&ID=" + dr["ID"].ToString(); break;
                    case "JoinStep12": dr["ID"] = "JoinParty/PotentialMember.aspx?AppllicationID=" + dr["AppllicationID"].ToString() + "&ID=" + dr["ID"].ToString(); break;
                    case "JoinStep24": dr["ID"] = "JoinParty/ProbationaryMember.aspx?AppllicationID=" + dr["AppllicationID"].ToString() + "&ID=" + dr["ID"].ToString(); break;
                    case "JoinStep36": dr["ID"] = "JoinParty/Regular.aspx?AppllicationID=" + dr["AppllicationID"].ToString() + "&ID=" + dr["ID"].ToString(); break;
                }
                dr["CreateTime2"] = Convert.ToDateTime(dr["CreateTime"]).ToString("yyyy-MM-dd HH:mm");
            }
            var json = JsonConvert.SerializeObject(dt);
            Response.Clear();
            Response.Write(json);
            Response.End();
        }
        private void WriteDataCount()
        {
            Response.Clear();
            Response.Write(partyjoinpublicity.GetListData(0, 10).Tables[1].Rows[0][0].ToString());
            Response.End();
        }
        #region 模块菜单
        /// <summary>
        /// 初始化module  如果通过url传参可不设置
        /// </summary>
        protected override void InitModule()
        {
            Module = "publicMessage";
            Category = "messagepublic";

        }
        #endregion

        /// <summary>
        /// 截取标题
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public string CutLongTitle(object obj, int length)
        {
            string title = Convert.ToString(obj);
            if (title.Length > length)
            {
                title = title.Substring(0, length) + "...";
            }
            return title;
        }
    }
}